package git.bds.nyc.applet.api.controller.demand;

import cn.easyes.core.biz.PageInfo;
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import git.bds.nyc.demand.mapper.ee.DemandEsMapper;
import git.bds.nyc.demand.model.ee.DemandEs;
import git.bds.nyc.page.PageParam;
import git.bds.nyc.page.PageResult;
import git.bds.nyc.product.model.es.ProductEs;
import git.bds.nyc.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author 成大事
 * @since 2023/4/22 10:02
 */
@Api(tags = "需求模块")
@Slf4j
@Validated
@RestController
@RequestMapping("/applet/demand")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class DemandController {

    private final DemandEsMapper demandEsMapper;


    /**
     * 底部需求数据 通过Es获取 分页
     *
     * @param pageParam 页面参数
     * @return {@link R}<{@link PageResult}<{@link ProductEs}>>
     */
    @ApiOperation("底部需求数据 通过Es获取 分页")
    @GetMapping("/getDemandPageByEs")
    public R<PageResult<DemandEs>> getDemandPageByEs(
            @Valid PageParam pageParam
    ){
        LambdaEsQueryWrapper<DemandEs> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.matchAllQuery();
        wrapper.orderByDesc(DemandEs::getCreateTime);
        PageInfo<DemandEs> productEsPageInfo = demandEsMapper.pageQuery(wrapper, pageParam.getPageNo().intValue(), pageParam.getPageSize().intValue());
        return R.ok(new PageResult<>(productEsPageInfo.getList(),(long) productEsPageInfo.getSize()));
    }
}
